package com.block.common.model.vo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;

@Data
public class ResultInfoVO {

    private String requestNo;

    private boolean success;

    private String respCode;

    private String respMsg;

    private JSONObject data;

    public static ResultInfoVO error(String msg){
        ResultInfoVO resultInfoVO = new ResultInfoVO();
        resultInfoVO.setSuccess(false);
        resultInfoVO.setRespCode("999");
        resultInfoVO.setRespMsg(msg);
        return resultInfoVO;
    }

    public static ResultInfoVO error(String code, String msg){
        ResultInfoVO resultInfoVO = new ResultInfoVO();
        resultInfoVO.setSuccess(false);
        resultInfoVO.setRespCode(code);
        resultInfoVO.setRespMsg(msg);
        return resultInfoVO;
    }

    public static ResultInfoVO errorToken(){
        ResultInfoVO resultInfoVO = new ResultInfoVO();
        resultInfoVO.setSuccess(false);
        resultInfoVO.setRespCode("201");
        resultInfoVO.setRespMsg("登陆超时，请重新登陆");
        return resultInfoVO;
    }

    public static ResultInfoVO success(){
        ResultInfoVO resultInfoVO = new ResultInfoVO();
        resultInfoVO.setSuccess(true);
        resultInfoVO.setRespCode("200");
        resultInfoVO.setRespMsg("成功");
        return resultInfoVO;
    }

    public static ResultInfoVO success(JSONObject data){
        ResultInfoVO resultInfoVO = new ResultInfoVO();
        resultInfoVO.setSuccess(true);
        resultInfoVO.setRespCode("200");
        resultInfoVO.setRespMsg("成功");
        resultInfoVO.setData(data);
        return resultInfoVO;
    }

    public ResultInfoVO setRequestNo(String requestNo){
        this.requestNo = requestNo;
        return this;
    }

    public String toResp(){
        return JSON.toJSONString(this);
    }
}
